<script type="text/javascript">
$(document).ready(function() {
	$('#authWaiting').dialog({
		bgiframe:	true,
		autoOpen:	false,
		modal:		true,
		width:		400
	});

	$('#registerUser').click(function() {
		$('#authWaiting').dialog('open');
		var password	= $('#password').val();
		var confPassword	= $('#confPassword').val();

		if( (password != "") && (confPassword != "") ) {
			if(password == confPassword) {
				$.ajax({
					data:		{
						name:			$('#name').val(),
						'password':		password,
					},
					dataType:	'json',
					error:		function(rq, status, error) {
						alert('There was a problem adding you as a user: ' + error);
					},
					success:	function(rsp, status) {
						if(rsp.status == 1) {
							window.location = "<?php echo $this->baseUrl(); ?>/";
						} else {
							$('#authWaiting').dialog('close');
							$('#authMessage').html('Error - ' + rsp.message);
						}
					},
					type:		'POST',
					url:		'<?php echo $this->baseUrl(); ?>/auth/newuser/finalize'
				});
			} else {
				$('#authMessage').html('The password and confirmation password do not match.');
				$('$confPassword').val("");
			}
		} else {
			$('#authMessage').html('Please enter both a password and a confirmation password.');
		}
		$('#authWaiting').dialog('close');
	});
});
</script>

<h1>Register New User</h1>

<div id="authMessage">
	<?php echo $this->message; ?>
</div>

<div style="margin-left: auto; margin-right: auto; width: 200px;" class="panel">
	<dl class="form">
		<dt>Username:</dt>
			<dd><input type="text" value="<?php echo $this->username; ?>" READONLY></dd>
		<dt>E-mail Address:</dt>
			<dd><input type="text" value="<?php echo $this->email; ?>" READONLY></dd>
		<dt>Name:</dt>
			<dd><input type="text" id="name" name="name" value="<?php echo $this->name; ?>"></dd>
		<dt>Password:</dt>
			<dd><input type="password" name="password" id="password"></dd>
		<dt>Confirm Password:</dt>
			<dd><input type="password" name="confPassword" id="confPassword"></dd>
	</dl>

	<button align="right" id="registerUser">Register New User</button>
</div>

<div id="authWaiting" title="Working...">
	Please wait while we finish registering your user...

	<p>
	<img src="<?php echo $this->baseUrl(); ?>/images/ajax-loader.gif">
</div>